package _.mail;

import org.budo.support.lang.util.StringUtil;
import org.springframework.util.Assert;

import lombok.Getter;
import lombok.Setter;

import org.budo.mail.util.MailAddressUtil;

/**
 * @author li
 * @version 1 (2014年7月4日 下午3:26:55)
 * @since Java7
 */
@Getter
@Setter
public abstract class AbstractMailSender implements MailSender {
    private Boolean debug = false;

    private String host;

    private String username;

    private String password;

    private String from;

    private String charset = "UTF-8";

    public String getHost() {
        if (null != this.host) {
            return this.host;
        }

        Assert.hasText(this.getUsername(), "#36 username can not be null");
        return MailAddressUtil.guessSendHost(this.getUsername());
    }

    public String getFrom() {
        return (!StringUtil.isEmpty(from) && !"null".equalsIgnoreCase(from)) ? from : this.getUsername();
    }
}